/* ------------------------------------------------------------------------
   file    :  prolint/rules/message.p
   by      :  Jurjen Dijkstra
   purpose :  Find "MESSAGE" statements, but suppress warnings for 
              AB-generated messages and for messages in ADM-includefiles
    -----------------------------------------------------------------

    Copyright (C) 2001,2002 Jurjen Dijkstra

    This file is part of Prolint.

    Prolint is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    Prolint is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with Prolint; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   ------------------------------------------------------------------------ */
  
{prolint/core/ruleparams.i}  

DEFINE VARIABLE IgnoreAppbuilderstuff AS LOGICAL NO-UNDO.

IgnoreAppbuilderstuff = LOGICAL ( DYNAMIC-FUNCTION ("ProlintProperty", "filters.IgnoreAppbuilderstuff")).

DEFINE TEMP-TABLE tt_abgenerated NO-UNDO 
    FIELD msg AS CHARACTER.
                     
IF IgnoreAppbuilderstuff THEN DO:
  /* create a tt_abgenerated record for each message that is generated by AB/UIB */                           
  CREATE tt_abgenerated.
  ASSIGN tt_abgenerated.msg = '"*~~.wrx":U':U.
  CREATE tt_abgenerated.
  ASSIGN tt_abgenerated.msg = '"* should only be RUN PERSISTENT.":U':U.
END.

RUN searchNode            (hTopnode,                /* "Program_root" node                 */
                           "InspectNode":U,         /* name of callback procedure          */
                           "MESSAGE":U).            /* list of statements to search, ?=all */

RETURN.

                           
PROCEDURE InspectNode :             
  /* purpose : callback from searchNode. Inspect the node found by searchNode */
  DEFINE INPUT  PARAMETER theNode        AS INTEGER NO-UNDO.
  DEFINE OUTPUT PARAMETER AbortSearch    AS LOGICAL NO-UNDO INITIAL NO.
  DEFINE OUTPUT PARAMETER SearchChildren AS LOGICAL NO-UNDO INITIAL NO.
  
  DEFINE VARIABLE child        AS INTEGER NO-UNDO.
  DEFINE VARIABLE abgenerated  AS LOGICAL NO-UNDO.
  DEFINE VARIABLE nodefilename AS CHARACTER NO-UNDO.
                         
  ASSIGN
    SearchChildren = FALSE
    child          = parserGetHandle()
    abgenerated    = FALSE.
                                                    
  nodefilename = RelativeFilename(parserGetNodeFilename(theNode)).
  IF (nodefilename MATCHES "src/adm/*~~.i":U) OR (nodefilename MATCHES "src/adm2/*~~.i":U) THEN 
     abgenerated = TRUE.
  ELSE
    IF IgnoreAppbuilderstuff THEN
      /* First child is "Form_item", second child might be the "QSTRING" that we are after. */
      IF parserNodeFirstChild(theNode,child)<>"" AND parserNodeFirstChild(child,child)<>"" THEN
        IF CAN-FIND(FIRST tt_abgenerated WHERE parserGetNodeText(child) MATCHES tt_abgenerated.msg) THEN 
           abgenerated = TRUE.

  IF (NOT abgenerated) THEN
    RUN PublishResult            (compilationunit,
                                  nodefilename,
                                  parserGetNodeLine(theNode), 
                                  "use MESSAGE only in debug-mode":T,
                                  rule_id).
    
  parserReleaseHandle(child).
    
END PROCEDURE.                            
